package com.wangjiacai.hqlQuery.hql.condition.where;

import com.wangjiacai.hqlQuery.hql.condition.Condition;
import com.wangjiacai.hqlQuery.util.HqlUtil;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

@Target({ElementType.FIELD})
@Retention(RetentionPolicy.RUNTIME)
@Condition(condition = NotEqual.NotEqualCondition.class,column = NotEqual.NotEqualCondition.class)
public @interface NotEqual {

    String column() default "";

    String hql() default "";

    class NotEqualCondition implements Condition.Where<NotEqual,Object>, Condition.Column<NotEqual> {
        @Override
        public String where(NotEqual notEqual,String property,String column,Object obj,Object value) {
            return notEqual.hql().equals("")?column+" != :"+property:column+" != ("+ HqlUtil.parseHql(notEqual.hql(),obj)+")";
        }

        @Override
        public String column(NotEqual notEqual, String property) {
            return notEqual.column().equals("")?property:notEqual.column();
        }
    }

}
